using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace M13.DataStructure
{
    public class UniqueIdDictionary<tKey1, tKey2> where tKey1 : struct where tKey2 : class
    {
        private List<tKey1> _key1S;
        private List<tKey2> _key2S;
        public int Count { get { return _key1S.Count; } private set { } }
        public UniqueIdDictionary()
        {
            _key1S = new List<tKey1>();
            _key2S = new List<tKey2>();
        }
        public void Add(tKey1 key1, tKey2 key2)
        {
            for(int i = 0; i < Count; i++)
            {
                if(!_key1S.Contains(key1) && !_key2S.Contains(key2))
                {
                    _key1S.Add(key1);
                    _key2S.Add(key2);
                }
                else
                {
                    Debug.LogError("��ͼ�����ֵ����Ѱ�����Ԫ��");
                }
            }
        }
        public tKey1 GetKey1(tKey2 key2)
        {
            int index = _key2S.IndexOf(key2);
            return _key1S[index];
        }
        public tKey2 GetKey2(tKey1 key1)
        {
            int index = _key1S.IndexOf(key1);
            return _key2S[index];
        }
        public void Remove(tKey1 key1)
        {
            tKey2 key2 = GetKey2(key1);
            if(_key1S.Contains(key1) && _key2S.Contains(key2))
            {
                _key1S.Remove(key1);
                _key2S.Remove(key2);
            }
            else
            {
                Debug.LogError("��ͼ�Ƴ��ֵ��в�������Ԫ��");
            }
        }
        public void Remove(tKey2 key2)
        {
            tKey1 key1 = GetKey1(key2);
            if (_key1S.Contains(key1) && _key2S.Contains(key2))
            {
                _key1S.Remove(key1);
                _key2S.Remove(key2);
            }
            else
            {
                Debug.LogError("��ͼ�Ƴ��ֵ��в�������Ԫ��");
            }
        }
    }
}